home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / MoreFiles 1.3.1 / FullPath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-16  |  6.9 KB  |  179 lines  |  [TEXT/MMCC]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines for dealing with full pathnames... if you really must.
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support
  7. **
  8. **    File:        FullPath.h
  9. **
  10. **    Copyright © 1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #ifndef __FULLPATH__
  23. #define __FULLPATH__
  24.  
  25. #include <Types.h>
  26. #include <Files.h>
  27.  
  28. /*
  29.     IMPORTANT NOTE:
  30.     
  31.     The use of full pathnames is strongly discouraged. Full pathnames are
  32.     particularly unreliable as a means of identifying files, directories
  33.     or volumes within your application, for two primary reasons:
  34.     
  35.     •     The user can change the name of any element in the path at
  36.         virtually any time.
  37.     •    Volume names on the Macintosh are *not* unique. Multiple
  38.         mounted volumes can have the same name. For this reason, the use of
  39.         a full pathname to identify a specific volume may not produce the
  40.         results you expect. If more than one volume has the same name and
  41.         a full pathname is used, the File Manager currently uses the first
  42.         mounted volume it finds with a matching name in the volume queue.
  43.     
  44.     In general, you should use a file’s name, parent directory ID, and
  45.     volume reference number to identify a file you want to open, delete,
  46.     or otherwise manipulate.
  47.     
  48.     If you need to remember the location of a particular file across
  49.     subsequent system boots, use the Alias Manager to create an alias
  50.     record describing the file. If the Alias Manager is not available, you
  51.     can save the file’s name, its parent directory ID, and the name of the
  52.     volume on which it’s located. Although none of these methods is
  53.     foolproof, they are much more reliable than using full pathnames to
  54.     identify files.
  55.     
  56.     Nonetheless, it is sometimes useful to display a file’s full pathname
  57.     to the user. For example, a backup utility might display a list of full
  58.     pathnames of files as it copies them onto the backup medium. Or, a
  59.     utility might want to display a dialog box showing the full pathname of
  60.     a file when it needs the user’s confirmation to delete the file. No
  61.     matter how unreliable full pathnames may be from a file-specification
  62.     viewpoint, users understand them more readily than volume reference
  63.     numbers or directory IDs.
  64.     
  65.     The following technique for constructing the full pathname of a file is
  66.     intended for display purposes only. Applications that depend on any
  67.     particular structure of a full pathname are likely to fail on alternate
  68.     foreign file systems or under future system software versions.
  69. */
  70.  
  71. /*****************************************************************************/
  72.  
  73. pascal    OSErr    GetFullPath(short vRefNum,
  74.                             long dirID,
  75.                             StringPtr name,
  76.                             short *fullPathLength,
  77.                             Handle *fullPath);
  78. /*    ¶ Get a full pathname to a volume, directory or file.
  79.     The GetFullPath function builds a full pathname to the specified
  80.     object. The full pathname is returned in the newly created handle
  81.     fullPath and the length of the full pathname is returned in
  82.     fullPathLength. Your program is responsible for disposing of the
  83.     fullPath handle.
  84.     
  85.     vRefNum            input:    Volume specification.
  86.     dirID            input:    Directory ID.
  87.     name            input:    Pointer to object name, or nil when dirID
  88.                             specifies a directory that's the object.
  89.     fullPathLength    output:    The number of characters in the full pathname.
  90.                             If the function fails to create a full
  91.                             pathname, it sets fullPathLength to 0.
  92.     fullPath        output:    A handle to the newly created full pathname
  93.                             buffer. If the function fails to create a
  94.                             full pathname, it sets fullPath to NULL.
  95.  
  96.     __________
  97.     
  98.     See also:    FSpGetFullPath
  99. */
  100.  
  101. /*****************************************************************************/
  102.  
  103. pascal    OSErr    FSpGetFullPath(FSSpec *spec,
  104.                                short *fullPathLength,
  105.                                Handle *fullPath);
  106. /*    ¶ Get a full pathname to a volume, directory or file.
  107.     The GetFullPath function builds a full pathname to the specified
  108.     object. The full pathname is returned in the newly created handle
  109.     fullPath and the length of the full pathname is returned in
  110.     fullPathLength. Your program is responsible for disposing of the
  111.     fullPath handle.
  112.     
  113.     spec            input:    An FSSpec record specifying the object.
  114.     fullPathLength    output:    The number of characters in the full pathname.
  115.                             If the function fails to create a full pathname,
  116.                             it sets fullPathLength to 0.
  117.     fullPath        output:    A handle to the newly created full pathname
  118.                             buffer. If the function fails to create a
  119.                             full pathname, it sets fullPath to NULL.
  120.  
  121.     __________
  122.     
  123.     See also:    GetFullPath
  124. */
  125.  
  126. /*****************************************************************************/
  127.  
  128. pascal OSErr FSpLocationFromFullPath(short fullPathLength,
  129.                                      const void *fullPath,
  130.                                      FSSpec *spec);
  131. /*    ¶ Get a FSSpec from a full pathname.
  132.     The FSpLocationFromFullPath function returns a FSSpec to the object
  133.     specified by full pathname. This function requires the Alias Manager.
  134.     
  135.     fullPathLength    input:    The number of characters in the full pathname
  136.                             of the target.
  137.     fullPath        input:    A pointer to a buffer that contains the full
  138.                             pathname of the target. The full pathname
  139.                             starts ith the name of the volume, includes
  140.                             all of the directory names in the path to the
  141.                             target, and ends with the target name.
  142.     spec            output:    An FSSpec record specifying the object.
  143.  
  144.     __________
  145.     
  146.     See also:    LocationFromFullPath
  147. */
  148.  
  149. /*****************************************************************************/
  150.  
  151. pascal OSErr LocationFromFullPath(short fullPathLength,
  152.                                   const void *fullPath,
  153.                                   short *vRefNum,
  154.                                   long *parID,
  155.                                   Str31 name);
  156. /*    ¶ Get an object's location from a full pathname.
  157.     The LocationFromFullPath function returns the volume reference number,
  158.     parent directory ID and name of the object specified by full pathname.
  159.     This function requires the Alias Manager.
  160.     
  161.     fullPathLength    input:    The number of characters in the full pathname
  162.                             of the target.
  163.     fullPath        input:    A pointer to a buffer that contains the full
  164.                             pathname of the target. The full pathname starts
  165.                             with the name of the volume, includes all of
  166.                             the directory names in the path to the target,
  167.                             and ends with the target name.
  168.     vRefNum            output:    The volume reference number.
  169.     parID            output:    The parent directory ID of the specified object.
  170.     name            output:    The name of the specified object.
  171.  
  172.     __________
  173.     
  174.     See also:    FSpLocationFromFullPath
  175. */
  176.  
  177. /*****************************************************************************/
  178.  
  179. #endif    /* __FULLPATH__ */